package org.kabeja.parser.entities;

import org.kabeja.dxf.entity.DXFEntity;
import org.kabeja.dxf.entity.DXFLeader;
import org.kabeja.dxf.helpers.Point;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 11:32
 */
public class DXFLeaderHandler extends AbstractEntityHandler {
    public static final int GROUPCODE_ARROW_HEAD_FLAG = 71;
    public static final int GROUPCODE_LEADER_PATH_TYPE = 72;
    public static final int GROUPCODE_LEADER_CREATION_FLAG = 73;
    public static final int GROUPCODE_HOOKLINE_DIRECTION_FLAG = 74;
    public static final int GROUPCODE_HOOKLINE_FLAG = 75;
    public static final int GROUPCODE_TEXT_HEIGHT = 40;
    public static final int GROUPCODE_TEXT_WIDTH = 41;
    public static final int GROUPCODE_COLOR_LEADER = 77;
    public static final int GROUPCODE_TEXT_ENTITY_REFERENCE = 340;
    public static final int GROUPCODE_HORIZONTAL_DIRECTION_X = 211;
    public static final int GROUPCODE_HORIZONTAL_DIRECTION_Y = 221;
    public static final int GROUPCODE_HORIZONTAL_DIRECTION_Z = 231;
    public static final int GROUPCODE_OFFSET_LAST_VERTEX_INSERTPOINT_X = 212;
    public static final int GROUPCODE_OFFSET_LAST_VERTEX_INSERTPOINT_Y = 222;
    public static final int GROUPCODE_OFFSET_LAST_VERTEX_INSERTPOINT_Z = 232;
    public static final int GROUPCODE_OFFSET_LAST_VERTEX_PLACEMENT_POINT_X = 213;
    public static final int GROUPCODE_OFFSET_LAST_VERTEX_PLACEMENT_POINT_Y = 223;
    public static final int GROUPCODE_OFFSET_LAST_VERTEX_PLACEMENT_POINT_Z = 233;
    protected DXFLeader leader;
    protected Point vertex;

    public DXFLeaderHandler() {
    }

    @Override
    public String getDXFEntityName() {
        return "LEADER";
    }

    @Override
    public void startDXFEntity() {
        this.leader = new DXFLeader();
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case 3:
                this.leader.setStyleNameID(var2.getValue());
                break;
            case 10:
                this.vertex = new Point();
                this.leader.addCoordinate(this.vertex);
                this.vertex.setX(var2.getDoubleValue());
                break;
            case 20:
                this.vertex.setY(var2.getDoubleValue());
                break;
            case 30:
                this.vertex.setZ(var2.getDoubleValue());
                break;
            case 40:
                this.leader.setTextHeight(var2.getDoubleValue());
                break;
            case 41:
                this.leader.setTextWidth(var2.getDoubleValue());
                break;
            case 71:
                this.leader.setArrowEnabled(var2.getBooleanValue());
                break;
            case 72:
                this.leader.setPathType(var2.getIntegerValue());
                break;
            case 73:
                this.leader.setCreationType(var2.getIntegerValue());
                break;
            case 74:
                this.leader.setHooklineDirecton(var2.getIntegerValue());
                break;
            case 75:
                this.leader.setHookline(var2.getBooleanValue());
                break;
            case 77:
                this.leader.setColor(var2.getIntegerValue());
                break;
            case 211:
                this.leader.getHorizontalDirection().setX(var2.getDoubleValue());
                break;
            case 212:
                this.leader.getLastOffsetInsertion().setX(var2.getDoubleValue());
                break;
            case 213:
                this.leader.getLastOffsetText().setX(var2.getDoubleValue());
                break;
            case 221:
                this.leader.getHorizontalDirection().setY(var2.getDoubleValue());
                break;
            case 222:
                this.leader.getLastOffsetInsertion().setY(var2.getDoubleValue());
                break;
            case 223:
                this.leader.getLastOffsetText().setY(var2.getDoubleValue());
                break;
            case 231:
                this.leader.getHorizontalDirection().setZ(var2.getDoubleValue());
                break;
            case 232:
                this.leader.getLastOffsetInsertion().setZ(var2.getDoubleValue());
                break;
            case 233:
                this.leader.getLastOffsetText().setZ(var2.getDoubleValue());
                break;
            case 340:
                this.leader.setTextID(var2.getValue());
                break;
            default:
                super.parseCommonProperty(var1, var2, this.leader);
        }

    }

    @Override
    public void parseObject(int var1, DXFValue var2, int type) {
        super.parseObjectProperty(var1, var2, type, this.leader);
    }

    @Override
    public DXFEntity getDXFEntity() {
        return this.leader;
    }

    @Override
    public void endDXFEntity() {
    }

    @Override
    public boolean isFollowSequence() {
        return false;
    }
}
